package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.product.RCIdentifiableNormalProductEntry;
import com.shrct.businessprocess.product.RCIdentifiableNormalProductEntryDAO;
import com.shrct.businessprocess.product.RCProductEntry;
import com.shrct.businessprocess.purchase.RCBudgetContract;
import com.shrct.businessprocess.purchase.RCIdentifiableNormallProductDeliverItem;
import com.shrct.businessprocess.purchase.RCProductDeliver;
import com.shrct.businessprocess.purchase.impl.RCIdentifiableProductDeliverItemImpl;
import com.shrct.businessprocess.purchase.proxy.RCIdentifiableNormallProductDeliverItemProxy;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("RCIDENTIFIABLENORMALLPRODUCTDELIVERITEM_TYPE")
public class RCIdentifiableNormallProductDeliverItemImpl extends RCIdentifiableProductDeliverItemImpl implements RCIdentifiableNormallProductDeliverItem {
  public RCIdentifiableNormallProductDeliverItemImpl() {
    super();
  }
  
  public RCIdentifiableNormallProductDeliverItemImpl(final RCProductDeliver deliver) {
    super( deliver);
    
  }
  
  public void performDeliver(final Date deliverDate) {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCIdentifiableNormalProductEntryDAO _bean = _beanFactory.<RCIdentifiableNormalProductEntryDAO>getBean(RCIdentifiableNormalProductEntryDAO.class);
    RCProductEntry _product = this.getProduct();
    RCProductDeliver _deliver = this.getDeliver();
    RCBudgetContract _contract = _deliver.getContract();
    RCEnterprise _customer = _contract.getCustomer();
    _bean.transferNormalPruduct(((RCIdentifiableNormalProductEntry) _product), _customer);
    RCProductEntry _product_1 = this.getProduct();
    RCProductDeliver _deliver_1 = this.getDeliver();
    String _location = _deliver_1.getLocation();
    _product_1.setLocation(_location);
    RCProductEntry _product_2 = this.getProduct();
    RCProductDeliver _deliver_2 = this.getDeliver();
    String _branch = _deliver_2.getBranch();
    _product_2.setBranch(_branch);
  }
  
  public void cancelDeliver() {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCIdentifiableNormalProductEntryDAO _bean = _beanFactory.<RCIdentifiableNormalProductEntryDAO>getBean(RCIdentifiableNormalProductEntryDAO.class);
    RCProductEntry _product = this.getProduct();
    _bean.cancelTransferNormalPruduct(((RCIdentifiableNormalProductEntry) _product));
  }
  
  public static RCIdentifiableNormallProductDeliverItem create(final RCProductDeliver deliver, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCIdentifiableNormallProductDeliverItem rCIdentifiableNormallProductDeliverItem = new com.shrct.businessprocess.purchase.impl.RCIdentifiableNormallProductDeliverItemImpl(
    	deliver
    );
    objectFactory.create(rCIdentifiableNormallProductDeliverItem);
    return rCIdentifiableNormallProductDeliverItem;			
    
  }
  
  public static RCIdentifiableNormallProductDeliverItem createRCIdentifiableNormallProductDeliverItemImpl(final RCProductDeliver deliver, final IObjectFactory objectFactory, final Procedure1<RCIdentifiableNormallProductDeliverItem> init) {
    com.shrct.businessprocess.purchase.RCIdentifiableNormallProductDeliverItem rCIdentifiableNormallProductDeliverItem = new com.shrct.businessprocess.purchase.impl.RCIdentifiableNormallProductDeliverItemImpl(
    	deliver
    );
    objectFactory.create(rCIdentifiableNormallProductDeliverItem);
    init.apply(rCIdentifiableNormallProductDeliverItem);
    
    return rCIdentifiableNormallProductDeliverItem;			
    
  }
  
  public RCIdentifiableNormallProductDeliverItemProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCIdentifiableNormallProductDeliverItemProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCIdentifiableNormallProductDeliverItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
